package ucadminlogic

import (
	"context"
	"github.com/zeromicro/go-zero/core/logx"
	"navi-mumbai/app/rpc/model/pg/usercenter"
	"navi-mumbai/app/rpc/usercenter/internal/svc"
	"navi-mumbai/app/rpc/usercenter/pb"
	"navi-mumbai/common/xerr"
)

type UpdateUserInviteConfigLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewUpdateUserInviteConfigLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateUserInviteConfigLogic {
	return &UpdateUserInviteConfigLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 创建UserInviteConfig设置
func (l *UpdateUserInviteConfigLogic) UpdateUserInviteConfig(in *pb.UpdateUserInviteConfigReq) (*pb.UpdateUserInviteConfigResp, error) {
	uf := usercenter.UserInviteConfig{
		Id:                     in.Id,
		SuperiorLevel:          in.SuperiorLevel,
		ReturnRatio:            in.ReturnRatio,
		ReturnNewRegisterMoney: in.ReturnNewRegisterMoney,
		RechargeLimit:          in.RechargeLimit,
		RechargeReturnMoney:    in.RechargeReturnMoney,
	}
	err := l.svcCtx.UserInviteConfigModel.Update(l.ctx, &uf)
	if err != nil {
		return nil, xerr.NewGrpcErrCodeMsg(xerr.DbError, err.Error())
	}
	return &pb.UpdateUserInviteConfigResp{}, nil
}
